#include <iostream>
using namespace std;
class Resource{
    public:
    Resource(){
        cout<<"init resource"<<endl;
        count = 0;
    }
    ~Resource()
    {
        cout<<"delete resource"<<endl;
    }
    void do_something()
    {
        cout<<"do something"<<endl;
    }
    private:
        int count;
};

void func(shared_ptr<Resource> ptr)
{
    ptr->do_something();
    cout<<ptr.use_count()<<endl;
}
void func1(shared_ptr<Resource>& ptr)
{
    ptr->do_something();
    cout<<ptr.use_count()<<endl;
}

int main()
{
    shared_ptr<Resource> res = make_shared<Resource>();
    cout<<res.use_count()<<endl;

    shared_ptr<Resource> res1 =res;
    cout<<res.use_count()<<" "<<res1.use_count()<<endl;

    func(res);
    cout<<res.use_count()<<endl;

    func1(res);
    cout<<res.use_count()<<endl;

    res1.reset();
    cout<<res.use_count()<<endl;
}